import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';

@Injectable()
export class CommonService {
  constructor(private readonly jwtService: JwtService) {}

  // 校验 token
  verifyToken(token: string): string {
    try {
      if (!token) return null;
      const id = this.jwtService.verify(token.replace('Bearer ', ''));
      return id;
    } catch (error) {
      return null;
    }
  }

  getToken(payload) {
    return {
      access_token: this.jwtService.sign(payload),
    };
  }
}
